﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Intelligent.OTC.Common;
using Intelligent.OTC.Common.Repository;
using Intelligent.OTC.Domain.DataModel;

namespace Intelligent.OTC.Business
{
    public class MailTemplateContext
    {
        public IRepository CommonRep { get; set; }

        public ITemplateParser Parser { get; set; }

        /// <summary>
        /// Get mail tempate wording: default pay cycle
        /// </summary>
        /// <param name="format"></param>
        /// <returns></returns>
        public string GetDefaultPayCycle(string format="yyyy/MM/dd")
        {
            PeroidService ps = SpringFactory.GetObjectImpl<PeroidService>("PeroidService");
            PeriodControl pc = ps.getcurrentPeroid();
            return pc.EndDate.ToString(format);
        }

        /// <summary>
        /// Get mail tempate wording: collector's signature
        /// </summary>
        /// <returns></returns>
        public string GetCollectorSignature()
        {
            string res = string.Empty;
            SysUser collector = Parser.GetContext("collector") as SysUser;

            if (collector == null)
            {
                return res;
            }

            var signature = CommonRep.GetQueryable<CollectorSignature>().Where(coll => coll.Collector == collector.EID).FirstOrDefault();
            if (signature != null)
            {
                return signature.Signature;
            }

            return res;
        }

        /// <summary>
        /// Get mail tempate wording: Contacts (mail to)
        /// </summary>
        /// <returns></returns>
        public string GetContacts()
        {
            return Parser.GetContext("contactNames") as string;
        }

        public string GetOldMailBody()
        {
            return Parser.GetContext("body") as string;
        }

        public string GetNow(string format = "yyyy/MM/dd")
        {
            return AppContext.Current.User.Now.ToString(format);
        }

        //=========added by alex body中显示附件名+Currency============
        public string GetAttachmentInfo()
        {
            return Parser.GetContext("attachmentInfo") as string;
        }

    }
}
